package com.controller;

import com.entity.Memo;
import com.service.IMemoService;
import com.vo.memoVo.AddMemoVo;
import com.vo.memoVo.MemoListRequestVo;
import com.vo.memoVo.UpdateMemoVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Describe 备忘录管理控制器
 */
@Controller
@RequestMapping("/memo")
public class MemoController {
    @Resource
    IMemoService memoService;

    @Resource
    HttpServletRequest request;

    /**
     * 获取备忘录列表信息
     */
    @RequestMapping("/getMemoList")
    @ResponseBody
    public List<Memo> getMemoList(MemoListRequestVo vo){
        Object session= request.getSession().getAttribute("user");
        if(session != null) {
            memoService.getMemoList(vo);
        }
        return null;
    }

    /**
     * 添加备忘录记录
     */
    @PostMapping("/addMemo")
    @ResponseBody
    public void addMemo(AddMemoVo addVo){
        Object session= request.getSession().getAttribute("user");
        if(session != null) {
            memoService.addMemo(addVo);
        }
    }

    /**
     * 修改备忘录信息
     */
    @PutMapping("/updateMemo")
    @ResponseBody
    public void updateMemo(UpdateMemoVo vo){
        Object session= request.getSession().getAttribute("user");
        if(session != null) {
            memoService.updateMemo(vo);
        }
    }

    /**
     * 删除备忘录记录
     */
    @DeleteMapping("/deleteMemo")
    @ResponseBody
    public void deleteMemo(Integer id){
        Object session= request.getSession().getAttribute("user");
        if(session != null) {
            memoService.deleteMemo(id);
        }
    }
}
